package cn.how2go.net.server.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * Created by Administrator on 2018/4/19.
 */
public class JT_8001 implements JTMessage {
    public JT_8001(){}
    public JT_8001(short seriaNo, short msgType, byte result) {
        this.seriaNo = seriaNo;
        this.msgType = msgType;
        this.result = result;
    }
    //应答流水号
    private short seriaNo;
    //应答消息类型
    private short msgType;
    //应答结果，0：成功/确认；1：失败；2：消息有误；3：不支持
    private byte result;

    public short getSeriaNo() {
        return seriaNo;
    }

    public void setSeriaNo(short seriaNo) {
        this.seriaNo = seriaNo;
    }

    public short getMsgType() {
        return msgType;
    }

    public void setMsgType(short msgType) {
        this.msgType = msgType;
    }

    public byte getResult() {
        return result;
    }

    public void setResult(byte result) {
        this.result = result;
    }

    @Override
    public byte[] write() {
        ByteBuf directBuf = Unpooled.directBuffer(16);
        directBuf.writeShort(seriaNo);
        directBuf.writeShort(msgType);
        directBuf.writeByte(result);
        byte[] bytess = new byte[directBuf.readableBytes()];
        directBuf.readBytes(bytess);
        directBuf.release();
        return bytess;
    }

    @Override
    public void read(byte[] bytes) {
        ByteBuf directBuf = Unpooled.directBuffer(16);
        directBuf.writeBytes(bytes);
        this.seriaNo = directBuf.readShort();
        this.msgType = directBuf.readShort();
        this.result = directBuf.readByte();
        directBuf.release();
    }

    @Override
    public short getBodyLength() {
        return 5;
    }
}
